<?php
class RSSFeed {
// VARIABLES
    // channel vars
    var $channel_url;
    var $channel_title;
    var $channel_description;
    var $channel_lang;
    var $channel_copyright;
    var $channel_date;
    var $channel_creator;
    var $channel_subject;   
    // image
    var $image_url;
    // items
    var $items = array();
    // number item
    var $nritems;
    
	// FUNCTIONS
    // constructor
    function RSSFeed() {
        $this->nritems=0;
        $this->channel_url='';
        $this->channel_title='';
        $this->channel_description='';
        $this->channel_lang='';
        $this->channel_copyright='';
        $this->channel_date='';
        $this->channel_creator='';
        $this->channel_subject='';
        $this->image_url='';
		$this->root_domain='';
    }   
    // set channel vars
    function SetChannel($url, $title, $description,$root_domain) 
    {
        $this->channel_url=$url;
        $this->channel_title=$title;
        $this->channel_description=$description;
		$this->root_domain=$root_domain;
        $this->channel_date=date("Y-m-d").'T'.date("H:i:s").'+07:00';
    }
    // set image
    function SetImage($url) 
    {
        $this->image_url=$url;  
    }
    // set item
    function SetItem($url, $title, $description,$datepost) 
    {
        $this->items[$this->nritems]['url']=$url;
        $this->items[$this->nritems]['title']=$title;
        $this->items[$this->nritems]['description']= $description;
        $this->items[$this->nritems]['datepost']= $datepost;
        $this->nritems++;   
    }
    // output feed
    function Output($hasEcho=false) 
    {
        $output =  '<?xml version="1.0" encoding="UTF-8"?>'."\n";
        $output .= '<rss version="2.0">'."\n";
        $output .= '<channel>'."\n";
        $output .= '<title>'.$this->channel_title.'</title>'."\n";
        $output .= '<description>'.$this->channel_description.'</description>'."\n";
        $output .= '<link>'.$this->channel_url.'</link>'."\n";
        $output .= '<copyright>'.$this->channel_title.'</copyright>'."\n";
        $output .= '<generator>'.$this->channel_title.'</generator>'."\n";
        
        //$output .= '<ttl>10</ttl>'."\n";
        
        //$output .= '<image>'."\n";
        //$output .= '<title>'.$this->channel_title.' Banner</title>'."\n";
        //$output .= '<url>/images/logofp.gif</url>'."\n";
		//$output .= '<link>'.$this->root_domain.'</link>'."\n";
        //$output .= '<width>150</width><height>80</height>'."\n";
        //$output .= '</image>'."\n";
        
        for($k=0; $k<$this->nritems; $k++) 
        {
            $output .= '<item>'."\n";
            $output .= '<title><![CDATA['.$this->items[$k]['title'].']]></title>'."\n";
            $output .= '<description><![CDATA['.$this->items[$k]['description'].']]></description>'."\n";
            $output .= '<link>'.$this->items[$k]['url'].'</link>'."\n";
            //$output .= '<guid isPermaLink="false">'.$this->items[$k]['url'].'</guid>'."\n";            
            $output .= '<pubDate>'.$this->items[$k]['datepost'].'</pubDate>'."\n";
            $output .= '</item>'."\n";  
        };
        
        $output .= '</channel>'."\n";
        $output .= '</rss>'."\n";
        if($hasEcho)
        {
            echo $output;
        }
        return $output;
    }
};

?>